/*
 *  Copyright (c) 2017 . Tencent 蓝鲸智云(BlueKing)
 */

package com.tencent.examples.web.rest;

import com.google.common.collect.Maps;
import com.tencent.bk.core.dto.paas.BkUserDto;
import com.tencent.bk.utils.bean.BeanUtil;
import com.tencent.examples.service.DemoService;
import com.tencent.examples.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 *
 */
@RestController
public class UserController extends BaseController {

    @Autowired
    private DemoService demoService;

    @RequestMapping(value = "/user/info/")
    public Object info() {
        BkUserDto user = getUser();
        Map<String, Object> map = Maps.newHashMap();
        BeanUtil.copy(user, map);
        map.put("demo", demoService.getDemo()); //只是演示如何利用配置项而已
        return map;
    }

    @RequestMapping(value = "/user/logout")
    public String logout() {
        //这里可以做业务想做的注销掉用户其他信息的操作
        //会话失效
        session.invalidate();
        return "redirect:/"; //跳首页会自动往登录页面跳
    }
}
